# ======================================================================
#
# Copyright (C) ADN
# Res.pl
# Description:
#  - Redemerare la sonde
#  - Restart the Sonde
#
# ======================================================================

use strict;
use Time::HiRes qw(sleep);
use LWP::UserAgent;
use ADN::CONF::Read;
use ADN::CONF::Path;
use Proc::Background;
use ADN::SERVER::StartUP;

my_get();
sleep 0.5;
my_launch();
exit;

# #######################
# LAUNCH THE SONDE
# #######################
sub my_launch {
  my ( $exe, $func );
  ( $exe , $func ) = ADN::SERVER::StartUP->folder();
  $func = $func . 'Server.pl';
  Proc::Background->new( $exe, $func, 'restart' );
  undef $func;
  undef $exe;
  return;
}

# #######################
# STOP THE SONDE
# #######################
sub my_get {
  my ( $ua, $req );
  my %folder;
  %folder = ADN::CONF::Read->new()->server();
  $ua = LWP::UserAgent->new( timeout => '10' );
  $ua->agent( 'ADN API' );
  $req = HTTP::Request->new( GET => 'http://127.0.0.1:' . $folder{port} . '/4200' );
  $ua->request($req);
  undef $ua;
  undef $req;
  undef %folder;
  return;
}
__END__
